<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('products')) {
            Schema::create('products', function (Blueprint $table) {
                $table->id();
                $table->foreignId('product_category_id')->nullable()->comment('产品分类ID');
                $table->string('serial_no')->comment('产品编号');
                $table->string('title')->comment('产品名称');
                $table->string('description')->nullable()->comment('产品描述');
                $table->string('image')->comment('产品图片');
                $table->json('images')->nullable()->comment('产品图片列表');
                $table->decimal('price', 10, 2)->comment('产品价格');
                $table->string('unit')->comment('产品单位');
                $table->integer('stock')->comment('产品库存');
                $table->integer('salenum')->default(0)->comment('销量');
                $table->text('content')->comment('产品详情');
                $table->json('items')->nullable()->comment('产品规格');
                $table->boolean('is_recommend')->default(false)->comment('是否推荐');
                $table->boolean('is_show')->default(true)->comment('是否上架');
                $table->integer('orderby')->default(0)->comment('排序');
                $table->integer('readnum')->default(0)->comment('阅读量');
                $table->timestamps();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
